﻿using DelonixRegia.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace DelonixRegia
{
    public partial class _default : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Account acc = Session["acc"] as Account;
            if (acc == null) Response.Redirect("SignIn.aspx?ReturnURL=" + HttpUtility.UrlEncode(HttpContext.Current.Request.Url.AbsoluteUri.Split('/').Last()));

            string username = CapitalizeFirstLetter(acc.username);
            lblUsername_NavBar.Text = username;
            lblUsername_NavBarExpand.Text = username;
            lblUsername_WelcomeMsg.Text = username;
            SetCurrent();

            switch (acc.userType)
            {
                case 2:
                    pnlManagement.Visible = true;
                    break;
                case 3:
                    pnlManagement.Visible = true;
                    pnlAdministrator.Visible = true;
                    break;
                default:
                    break;
            }
        }

        public string CapitalizeFirstLetter(string s)
        {
            if (String.IsNullOrEmpty(s))
                return s;
            if (s.Length == 1)
                return s.ToUpper();
            return s.Remove(1).ToUpper() + s.Substring(1);
        }

        private void SetCurrent()
        {
            var pageName = Request.Url.ToString().Split('/').Last();
            HtmlGenericControl li = new HtmlGenericControl("li");
            li.Attributes.Add("class", "active");

            switch (pageName)
            {
                case "Default.aspx":
                    homepageLink.Attributes["class"] = "active";
                    break;
                case "RoomAvailability.aspx":
                    roomAvailabilityLink.Attributes["class"] = "active";
                    li.InnerText = "Room Availability";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "RoomBooking.aspx":
                    roomBookingLink.Attributes["class"] = "active";
                    li.InnerText = "Room Booking";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "RoomCheckout.aspx":
                    roomCheckoutLink.Attributes["class"] = "active";
                    li.InnerText = "Room Checkout";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "AccountManagement.aspx":
                    accManagementLink.Attributes["class"] = "active";
                    li.InnerText = "Account Management";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "RoomStatus.aspx":
                    li.InnerText = "Room Status Report";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "RoomGuest.aspx":
                    li.InnerText = "Room Guest(s) Report";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "AllRoomGuest.aspx":
                    li.InnerText = "All Room Guest(s) Report";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "RoomOccupancy.aspx":
                    li.InnerText = "Room Occupancy Report";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "HousekeepingReport.aspx":
                    li.InnerText = "Housekeeping Report";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "FindGuest.aspx":
                    li.InnerText = "Find Guest";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "ModifyGuestRecord.aspx":
                    li.InnerText = "Modify Guest Record";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "ModifyRoomDetail.aspx":
                    li.InnerText = "Modify Room Detail";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "NewStaff.aspx":
                    li.InnerText = "New Staff";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "SearchStaff.aspx":
                    li.InnerText = "Search Staff";
                    olBreadcrumb.Controls.Add(li);
                    break;
                case "StaffSchedule.aspx":
                    li.InnerText = "Staff Schedule";
                    olBreadcrumb.Controls.Add(li);
                    break;
            }

            li.Dispose();
        }
    }
}